﻿using System;

namespace mki.Backup.Helper.Extensions
{
	public static class ExceptionExtension
	{
		#region Methods (1)

		// Public Methods (1) 

		/// <summary>
		/// Gets all messages (InnerException) from an <see cref="T:System.Exception"/>.
		/// </summary>
		/// <param name="exception">The <see cref="T:System.Exception"/> to get the messages from.</param>
		/// <returns>A <see cref="T:System.String"/> containing all messages from the given exception</returns>
		public static String GetAllMessages(this Exception exception)
		{
			var message = exception.Message;
			if (exception.InnerException != null)
			{
				message = String.Format("{0}\n->{1}", exception.Message, GetAllMessages(exception.InnerException));
			}

			return message;
		}

		#endregion Methods
	}
}
